<template>
	<view class="mainpadding beijingse">
		<u-keyboard ref="uKeyboard" mode="car" :show="carShow" @confirm="carShow=false"  @close="carShow=false"  @cancel="carShow=false" @change="valChange" @backspace="backspace"></u-keyboard>
		<view class="flexleft">
			<view class="line"></view>
			<view class="titletext bold hei_text margin_left1">基本信息</view>
		</view>
		<view class="flexbetween mainpadding ffffff margin_top radius" @click="pickerdzshow=true">
			<view class="ershib">城市</view>
			<view class="flexleft" style="justify-content: flex-end;">
				<input class="inputs  margin_right1" type="text" style="text-align: right;" placeholder="请选择服务城市"
					disabled v-model="city_text">
				<u-icon name="arrow-right" size="16" color="#999"></u-icon>
			</view>
		</view>
		<view class="flexbetween mainpadding ffffff radius margin_top">
			<view class="ershib">姓名</view>
			<input class="inputs " type="text" style="text-align: right;" placeholder="请输入真实姓名" v-model="usernmae">
		</view>
		<view class="flexbetween mainpadding ffffff radius margin_top" @click="carShow=true">
			<view class="ershib">车牌号</view>
			<input class="inputs " type="text" placeholder="请输入车牌号" disabled="" style="text-align: right;"
				v-model="cph">
		</view>
		<view class="flexbetween mainpadding ffffff radius margin_top">
			<view class="ershib">车型</view>
			<input class="inputs  margin_right1" type="text" style="text-align: right;" placeholder="请输入车型" v-model="cx" >
		</view>
		<view class="flexleft margin_top">
			<view class="line"></view>
			<view class="titletext bold hei_text margin_left1">资质上传</view>
		</view>
		<view class="flexbetween flex_wrap">
			<view class="scsfz margin_top" @click="uploadImg(1,idcrad_image,idcrad_image_text)">
				<image src="@/static/image/system/up1.png" mode="" v-if="!idcrad_image.length"></image>
				<image :src="idcrad_image_text[0]" mode="" v-if="idcrad_image.length"></image>
			</view>
			<view class="scsfz margin_top" @click="uploadImg(1,jsz_image,jsz_image_text)">
				<image src="@/static/image/system/up2.png" mode="" v-if="!jsz_image.length"></image>
				<image :src="jsz_image_text[0]" mode="" v-if="jsz_image.length"></image>
			</view>
			<view class="scsfz margin_top" @click="uploadImg(1,xsz_image,xsz_image_text)">
				<image src="@/static/image/system/up3.png" mode="" v-if="!xsz_image.length"></image>
				<image :src="xsz_image_text[0]" mode="" v-if="xsz_image.length"></image>
			</view>
			<view class="scsfz margin_top" @click="uploadImg(1,rchz_image,rchz_image_text)">
				<image src="@/static/image/system/up4.png" mode="" v-if="!rchz_image.length"></image>
				<image :src="rchz_image_text[0]" mode="" v-if="rchz_image.length"></image>
			</view>
		</view>
		<!-- 固定底部 -->
		<view class="margin_top" @click.stop="smrz">
			<view class="submitbtn">提交审核</view>
		</view>
		<pickercity :messageInfo="{pickerdzshow:pickerdzshow}" @surecity="surecity"></pickercity>
		
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				carShow:false,
				pickerdzshow:false,
				cityinfo:{},
				city_text:"",
				usernmae:"",
				cph:"",
				cx:"",
				idcrad_image:[],
				jsz_image:[],
				xsz_image:[],
				rchz_image:[],
				idcrad_image_text:[],
				jsz_image_text:[],
				xsz_image_text:[],
				rchz_image_text:[],
			}
		},
		methods: {
			surecity(e) {
				this.pickerdzshow = false
				if(e){
					this.cityinfo = e
					this.city_text = e.provence + "/" + e.city
				}
				console.log(e);
			},
			// 按键被点击(点击退格键不会触发此事件)
			valChange(val) {
				// 将每次按键的值拼接到value变量中，注意+=写法
				this.cph += val;
			},
			// 退格键被点击
			backspace() {
				// 删除cph的最后一个字符
				if (this.cph.length) this.cph = this.cph.substr(0, this.cph.length - 1);
			},
			// 实名认证
			smrz() {
				uni.showLoading({
					title: '请稍候...',
					mask: true
				})
				if (this.city_text == "") {
					uni.hideLoading()
					httpRequest.toast("请选择服务城市")
					return
				}
				if (this.usernmae == "") {
					uni.hideLoading()
					httpRequest.toast("请输入真实姓名")
					return
				}
				// if (this.idcrad_image == "") {
				// 	uni.hideLoading()
				// 	httpRequest.toast("请输入身份证号")
				// 	return
				// }
				// let reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
				// if (reg.test(this.idcrad_image) === false) {
				// 	httpRequest.toast("请输入正确的身份证号")
				// 	uni.hideLoading()
				// 	return false;
				// }
				if (this.cph == "") {
					uni.hideLoading()
					httpRequest.toast("请输入车牌号")
					return
				}
				if (this.cx == "") {
					uni.hideLoading()
					httpRequest.toast("请输入车型")
					return
				}
				if (this.idcrad_image.length == 0) {
					uni.hideLoading()
					httpRequest.toast("请上传身份证照片")
					return
				}
				if (this.jsz_image.length == 0) {
					uni.hideLoading()
					httpRequest.toast("请上传驾驶证照片")
					return
				}
				if (this.xsz_image.length == 0) {
					uni.hideLoading()
					httpRequest.toast("请上传行驶证照片")
					return
				}
				if (this.rchz_image.length == 0) {
					uni.hideLoading()
					httpRequest.toast("请上传人车合照")
					return
				}
				httpRequest.request('/api/user/shopApply', 'GET', {
					province_id:this.cityinfo.provenceid,
					city_id:this.cityinfo.cityid,
					usernmae:this.usernmae,
					cph:this.cph,
					cx:this.cx,
					idcrad_image:this.idcrad_image[0],
					jsz_image:this.jsz_image[0],
					xsz_image:this.xsz_image[0],
					rchz_image:this.rchz_image[0]
				}, false, false, true).then(res => {
					if (res.code == 1) {
						httpRequest.toast(res.msg)
						setTimeout(() => {
							uni.navigateBack(1)
						}, 1000)
					}
				}).catch(err => {
					uni.hideLoading()
					httpRequest.toast(err.msg);
				})
			},
			uploadImg(value, upImgs, upImgs_text) {
				let _this = this;
				uni.showActionSheet({
					itemList: ['相机', '相册'],
					success: function(res) {
						// 选择相机走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(1, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs, upImgs_text)
								}
							}).catch(err => {});
						}
						// 选择相册走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(1, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs, upImgs_text)
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			uploadImageService(url, upImg, upImgs_text) {
				let _this = this;
				httpRequest.uploadFile('/api/common/upload', url).then(res => {
					let image_item = res.fullurl;
					upImg.splice(0,1)
					upImgs_text.splice(0,1)
					upImg.push(res.url);
					upImgs_text.push(image_item);
					console.log(this.rchz_image_text,999);
				}).catch(err => {});
			},
			uploadImgtext() {
				let _this = this;
				uni.showActionSheet({
					itemList: ['相机', '相册'],
					success: function(res) {

						// 选择相机走0
						if (res.tapIndex == 0) {
							httpRequest.chooseImage(1, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageServicetext(res[i])
								}
							}).catch(err => {});
						}
						// 选择相册走1
						if (res.tapIndex == 1) {
							httpRequest.chooseImage(1, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {

									_this.uploadImageServicetext(res[i])
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			// 详情转载
			uploadImageServicetext(url) {
				let _this = this;
				httpRequest.uploadFile('/api/Common/upload', url).then(res => {
					let image_item = res.fullurl;
					this.upImgtext = image_item

				}).catch(err => {});
			},
			// 跳转审核状态页面
			/* 	tzshz() {
					uni.navigateTo({
						url: '/pages/mypage/shenheshangjrz'
					})
				}, */
			confirmSex(e) { //选择性别
				this.sex = e.value[0]
				this.show = false
			}
		}
	}
</script>

<style lang="scss" scoped>
	.scsfz {
		width: 48%;
		height: 291rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.ershib {
		font-size: 28rpx;
		font-family: PingFang SC-Heavy, PingFang SC;
		font-weight: 800;
		color: #000000;
	}

	.inputs {
		width: 60%;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
	}
</style>